package TankGame;
// 坦克大战
import javax.swing.*;

public class TankGame extends JFrame {
    private JPanel startPanel;
    private GamePanel gamePanel;
    private boolean isGameOver;

    public TankGame() {
        setTitle("坦克大战");
        setSize(800, 600);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null); // 居中显示窗口
        setResizable(false);

        startPanel = new StartPanel(this);
        gamePanel = new GamePanel(this);
        isGameOver = false;

        setContentPane(startPanel);
        setVisible(true);
    }

    public void startGame() {
        setVisible(false); // 隐藏当前窗口
        setContentPane(gamePanel);
        revalidate(); // 强制重新布局
        repaint(); // 强制重绘
        gamePanel.requestFocusInWindow();
        gamePanel.startGameLoop();
        setVisible(true); // 显示新的内容
    }

    public void gameOver(boolean isVictory) {
        isGameOver = true;
        String message = isVictory ? "游戏结束，胜利！" : "游戏结束，失败！";
        JOptionPane.showMessageDialog(this, message, "提示", JOptionPane.INFORMATION_MESSAGE);
        System.exit(0);
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            new TankGame(); // 创建并显示游戏窗口
        });
    }
}